package xyz.yuanjilu.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import xyz.yuanjilu.entity.GroovyScriptEntity;
import xyz.yuanjilu.service.GroovyScript;
import xyz.yuanjilu.service.GroovyService;
@Service
public class GroovyServiceImpl implements GroovyService{
	
	Logger logger= LoggerFactory.getLogger(getClass());

	@Autowired
	private Map<String, GroovyScript> scrptsMap;
	@Autowired
	private List<GroovyScript> scrpts;
	@PostConstruct
	public void init(){
		
		logger.info("启动脚本控制器，开始加载脚本");
		for (GroovyScript groovyScript : scrpts) {
			logger.info("加载脚本{},版本为{}",groovyScript.getScriptName(),groovyScript.getScriptVersion());
		}
		logger.info("启动脚本控制器，完成加载脚本");
	}
	@Override
	public List<GroovyScriptEntity> queryList(Map<String, Object> map) {
		List<GroovyScriptEntity> GroovyScriptEntitys=new ArrayList<GroovyScriptEntity>();
		for (GroovyScript groovyScript : scrpts) {
			GroovyScriptEntity groovyScriptEntity = new GroovyScriptEntity();
			groovyScriptEntity.setScriptName(groovyScript.getScriptName());
			groovyScriptEntity.setScriptStatus(groovyScript.getScriptStatus());
			groovyScriptEntity.setScriptVersion(groovyScript.getScriptVersion());
			GroovyScriptEntitys.add(groovyScriptEntity);
		}
		return GroovyScriptEntitys;
	}

	@Override
	public int queryTotal(Map<String, Object> map) {
		return scrpts.size();
	}

}
